#include<iostream>
#include<string>
using std::cout;
using std::endl;

class Student
{
private:
    int num;
    std::string name;
    double math;
    double english;
    double cpp;
    static int numbersum;//静态数据
public:
    
    Student() {}
    Student(int num,std::string name,double math,double english,double cpp)//构造函数 与setstudent作用相同
        :num(num),name(name),math(math),english(english),cpp(cpp) { numbersum++; }
    int GetNumberSum() { return numbersum; }
    void setstudent(int num,std::string name,double math,double english,double cpp)
    {
        this->num=num;
        this->name=name;
        this->math=math;
        this->english=english;
        this->cpp=cpp;
    }
    void InfoPrint()
    {
        cout<<this->num<<'\t';
        cout<<this->name<<'\t';
        cout<<this->math<<'\t';
        cout<<this->english<<'\t';
        cout<<this->cpp<<endl;
    }
    void setcpp(double cpp)
    {
        this->cpp=cpp;
    }
    double getmath()
    {
        return math;
    }
    double getenglish()
    {
        return english;
    }
    double getcpp()
    {
        return cpp;
    }
};

int Student::numbersum=0;//初始化静态数据

double GetAverage(Student &student)//同一个学生三科目平均分
{
    return (student.getmath()+student.getenglish()+student.getcpp())/3;
}

double GetAverage2(Student ss[],int n,int flag)//多个学生某科目平均分
{
    double sum=0;
    if(flag==1) 
    {
        for(int i=0;i<n;i++)
        {
            sum+=ss[i].getcpp();
        }   
    }
    
    if(flag==2) 
    {
        for(int i=0;i<n;i++)
        {
            sum+=ss[i].getmath();
        }   
    }

    if(flag==3) 
    {
        for(int i=0;i<n;i++)
        {
            sum+=ss[i].getenglish();
        }   
    }
    return sum/n;
}

void changemark(Student &student,double cpp)//函数参数值传递演示
{
    student.setcpp(cpp);
}

int main()
{
    Student student,s2,s3;
    student.setstudent(1,"Jack",100,100,100);
    s2.setstudent(2,"David",55,66,99);
    s3.setstudent(3,"Michael",78,92,45);
    
    Student test(4,"test",99,88,77);
    Student test2(4,"test",99,88,77);
    //test.InfoPrint();
    //cout<<test.GetNumberSum()<<endl;
    //student.InfoPrint();
    //cout<<student.getmath()<<endl;
    //cout<<GetAverage(student)<<endl;
    //cout<<GetAverage2(student,s2,s3,3)<<endl;

    /*Student ss[3];
    ss[0].setstudent(1,"Jack",100,100,100);
    ss[1].setstudent(2,"David",55,66,99);
    ss[2].setstudent(3,"Michael",78,92,45);
    cout<<"cpp"<<'\t'<<GetAverage2(ss,3,1)<<endl;
    cout<<"math"<<'\t'<<GetAverage2(ss,3,2)<<endl;
    cout<<"english"<<'\t'<<GetAverage2(ss,3,3)<<endl;*/

    Student *p;
    p=&student;
    cout<<student.getcpp()<<endl;
    changemark(student,90);
    cout<<student.getcpp()<<endl;
    return 0;
}